<script lang="ts">
//使用<keep-alive></keep-alive>缓存路由必须显式的声明name
export default {
	name: 'stockin',
};
</script>

<script setup lang="ts">
import { Plus, Refresh, Setting, EditPen, Delete, InfoFilled, Document, Check } from '@element-plus/icons-vue';
import { reactive, ref, onMounted, nextTick, computed, toRaw } from 'vue';
import { get_purchasebillinfo, get_basicsinfo, Add_PurchaseBill, checkImportData, Add_basicsinfo, Get_IdByFieldAndValue, Confirm_PurchaseBill, Cancel_PurchaseBill, delete_purchasebillinfo, update_purchasebillinfo, update_PurchaseDetailinfo, delete_PurchaseDetailinfo } from '../../request/api';
import type { ElForm, ElTable, ElUpload } from 'element-plus';
import { ElMessage } from 'element-plus';
import { main } from '@popperjs/core';
import { filterEmptyValues, validateData } from '../../common/common';
import * as XLSX from 'xlsx/xlsx.mjs';

//搜索表单
const roleseachform = reactive({
	billnumber: '',
	productiondate: [],
});

//所有的基础信息
const basics = reactive({
	branch: [], //分店
	supplier: [], //供应商
	goodcategory: [], //商品种类
	goodsseries: [], //商品系列
	goodsbrand: [], //商品品牌
	goodsgrade: [], //商品成色
	stoneinlay: [], //宝石镶法
	stonecategory: [], //宝石分类
	stoneclarity: [], //宝石净度
	stonecolor: [], //宝石颜色
	stonecut: [], //宝石切工
	stoneshape: [], //宝石形状
});

//明细表抽屉开关
const detaildrawer = ref(false);
//新增明细项目dialog开关
const detaildialog = ref(false);

//加载开关
const loading = ref(false);
//表格列表
const tabledata = ref([]);
//进货单状态
const billstate = ref();
//明细表格
const detailtabledata = ref([]);
//弹出框类型0是新增1是修改
const dialogtype = ref(0);
//弹出框真假
const maindrawer = ref(false);
//当前页
const currentPage = ref(1);
//总页数
const total = ref(0);
//每页显示条目个数
const pageSize = ref(10);
//每页多少条
const size = ref('');

//单据主表表单
const mainform = reactive({
	PurchaseBill_PurchaseDate: '', //进货日期
	PurchaseBill_branch_id: '', //分店
	PurchaseBill_supplier_id: '', //供应商
	PurchaseBill_remark: '', //备注
});
//点击修改时主表表单
const updatemainform = reactive({
	PurchaseBill_PurchaseDate: '', //进货日期
	PurchaseBill_branch_id: '', //分店
	PurchaseBill_supplier_id: '', //供应商
	PurchaseBill_remark: '', //备注
});
//明细表表单
const detailform = reactive({
	PurchaseDetailBill_name: '', //品名
	PurchaseDetailBill_CertificateNo: '', //证书号
	PurchaseDetailBill_StyleNumber: '', //款号
	PurchaseDetailBill_RingSize: '', //手寸
	PurchaseDetailBill_OriginalNumber: '', //原编号
	PurchaseDetailBill_TotalWeight: '', //总重
	PurchaseDetailBill_GoldWeight: '', //金重
	PurchaseDetailBill_GoldPrice: '', //金价
	PurchaseDetailBill_WearRate: '', //耗损率
	PurchaseDetailBill_CleanGoldPrice: '', //净金额
	PurchaseDetailBill_StoneInlay_id: '', //镶法
	PurchaseDetailBill_StoneShape_id: '', //形状
	PurchaseDetailBill_StoneColor_id: '', //颜色
	PurchaseDetailBill_MainStoneCategory_id: '', //主石类别
	PurchaseDetailBill_MinStonePrice: '', //主石单价
	PurchaseDetailBill_MainStoneTotalPrice: '', //主石价格
	PurchaseDetailBill_StoneClarity_id: '', //净度
	PurchaseDetailBill_StoneCut_id: '', //车工
	PurchaseDetailBill_MainStoneWeight: '', //主石重
	PurchaseDetailBill_MinStoneQuantity: '', //主石数量
	PurchaseDetailBill_AccessoryCategory_id: '', //副石类别
	PurchaseDetailBill_AccessoryStoneWeight: '', //副石重
	PurchaseDetailBill_AccessoryStoneQuantity: '', //副石数量
	PurchaseDetailBill_AccessoryStonePrice: '', //副石单价
	PurchaseDetailBill_AccessoryStoneTotalPrice: '', //副石价格
	PurchaseDetailBill_ProcessCost: '', //加工费
	PurchaseDetailBill_CertificateCost: '', //证书费
	PurchaseDetailBill_OtherCost: '', //其他费
	PurchaseDetailBill_cost: '', //成本
	PurchaseDetailBill_SalesRatio: '', //销售倍率
	PurchaseDetailBill_SalesPrice: '', //销售总价
	PurchaseDetailBill_GoodsGrade_id: '', //商品成色
	PurchaseDetailBill_GoodsBrand_id: '', //商品品牌
	PurchaseDetailBill_GoodsCategory_id: '', //商品分类
	PurchaseDetailBill_GoodsSeries_id: '', //系列
	PurchaseDetailBill_PriceMethod: '', //计价方式
	PurchaseDetailBill_MSPriceMethod: '', //主石计价方式
	PurchaseDetailBill_ASPriceMethod: '', //副石计价方式
	PurchaseDetailBill_CostMethod: '', //工费计价方式
});
//点击修改时明细表表单
const updatedetailform = reactive({
	...detailform,
});
console.log(updatedetailform);
//明细表验证规则
const detailformrule = reactive({
	PurchaseDetailBill_GoodsCategory_id: [{ required: true, message: '商品种类不能为空', trigger: 'change' }],
	PurchaseDetailBill_name: [{ required: true, message: '商品名称不能为空', trigger: 'blur' }],
	PurchaseDetailBill_SalesPrice: [{ required: true, message: '销售价格不能为空', trigger: 'blur' }],
	PurchaseDetailBill_PriceMethod: [{ required: true, message: '计价方式不能为空', trigger: 'change' }],
});

//新增和修改的表单
const form = reactive({
	customer_name: '',
	customer_sex: '1',
	customer_phone: '',
	customer_birthday: null,
	customer_email: '',
	customer_address: '',
	customer_qq: '',
	customer_remark: '',
});
//表单规则
const rules = reactive({
	customer_name: [
		{
			required: true,
			message: '客户名不能为空',
			trigger: 'blur',
		},
	],
});
//当前列id
const id = ref(0);

type FormInstance = InstanceType<typeof ElForm>;
const tableRef = ref<InstanceType<typeof ElTable>>();
const formref = ref<FormInstance>();

const detailformref = ref<FormInstance>(); //明细表验证
//页面进入请求数据
const { data } = await get_purchasebillinfo(currentPage.value, pageSize.value);
if (data.code == 200) {
	console.log(data.data);
	total.value = data.data.total;
	tabledata.value = data.data.data;
	console.log(data);
}
//页面进入请求基础数据
const { data: data1 } = await get_basicsinfo();
if (data1.code == 200) {
	// console.log(data1.data.branch)
	basics.branch = data1.data.branch;
	basics.supplier = data1.data.supplier;
	basics.goodcategory = data1.data.goodcategory;
	basics.goodsbrand = data1.data.goodsbrand;
	basics.goodsgrade = data1.data.goodsgrade;
	basics.goodsseries = data1.data.goodsseries;
	basics.stoneinlay = data1.data.stoneinlay;
	basics.stonecategory = data1.data.stonecategory;
	basics.stoneclarity = data1.data.stoneclarity;
	basics.stonecolor = data1.data.stonecolor;
	basics.stonecut = data1.data.stonecut;
	basics.stoneshape = data1.data.stoneshape;

	//如果有数据就默认选中第一项,没有就不要赋值否则会出现错误
	if (data1.data.branch.length > 0) {
		mainform.PurchaseBill_branch_id = data1.data.branch[0].branch_id; //分店默认值
		mainform.PurchaseBill_supplier_id = data1.data.supplier[0].supplier_id; //供应商默认值
	}



	// 拼接成一个完整的日期字符串（YYYY-MM-DD）
	const currentDate = `${new Date().getFullYear()}-${(new Date().getMonth() + 1).toString().padStart(2, '0')}-${new Date().getDate().toString().padStart(2, '0')}`;

	mainform.PurchaseBill_PurchaseDate = currentDate; //采购日期默认值
}

//分店筛选的数组
const branchArr = ref([]);
basics.branch.forEach((element) => {
	branchArr.value.push({
		text: element.branch_name,
		value: element.branch_id,
	});
});

//状态筛选
const state = ref(undefined);
//分店筛选
const branchF = ref(undefined);
//刷新
const refreshtable = async (currentPage, pageSize, begindate?, enddate?, billnumber?) => {
	loading.value = true;
	const { data } = await get_purchasebillinfo(currentPage, pageSize, begindate, enddate, billnumber, state.value, branchF.value);
	loading.value = false;
	if (data.code == 200) {
		console.log(data.data);
		total.value = data.data.total;
		tabledata.value = data.data.data;
	}
};
//监听current-page事件
const handleCurrentChange = async (newpage) => {
	refreshtable(newpage, pageSize.value);
};

//监听page-size每页条数
const handleSizeChange = async (pagesize) => {
	refreshtable(currentPage.value, pagesize);
};
//点击删除按钮
const delclick = async (row) => {
	const { data } = await delete_customerinfo(row.customer_id);
	if (data.code == 200) {
		ElMessage.success(data.msg);
		refreshtable(currentPage.value, pageSize.value);
	} else {
		ElMessage.error(data.msg);
	}
};

//点击修改按钮
const updateclick = (row) => {
	dialogtype.value = 1;
	dialogflag.value = true;
	nextTick(() => {
		form.customer_name = row.customer_name;
		form.customer_sex = row.customer_sex;
		form.customer_phone = row.customer_phone;
		form.customer_birthday = row.customer_birthday;
		form.customer_email = row.customer_email;
		form.customer_qq = row.customer_qq;
		form.customer_remark = row.customer_remark;
		form.customer_address = row.customer_address;
	});
	id.value = row.customer_id;
};

//点击新增或修改弹出框的确认按钮
const dialogclick = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.validate(async (valid) => {
		if (valid) {
			//新增
			if (dialogtype.value == 0) {
				const { data } = await insert_customerinfo(form);

				if (data.code == 200) {
					ElMessage.success(data.msg);

					refreshtable(currentPage.value, pageSize.value);
					formEl.resetFields();
					dialogflag.value = false;
				} else {
					ElMessage.error(data.msg);
				}
			} else if (dialogtype.value == 1) {
				//修改
				const { data } = await update_customerinfo(id.value, form);
				if (data.code == 200) {
					ElMessage.success(data.msg);
					formEl.resetFields();
					refreshtable(currentPage.value, pageSize.value);
					dialogflag.value = false;
				} else {
					ElMessage.error(data.msg);
					// formEl.resetFields();
				}
			}
		} else {
			console.log('验证失败');
		}
	});
};

//点击状态开关
const switchlick = async (row) => {
	id.value = row.customer_id;
	let updatedata = {
		customer_switch: row.customer_switch,
	};

	const { data } = await update_customerinfo(id.value, updatedata);

	if (data.code == 200) {
		ElMessage.success(data.msg);
		console.log('dsad');
	} else {
		ElMessage.error(data.msg);
		refreshtable(currentPage.value, pageSize.value);
	}
};

//关闭模态框之前清空表单数据
const beforeclosedialog = (done) => {
	//清空表单数据
	formref.value!.resetFields();
	return done(false);
};

//格式化时间
const formatterdate = (row, colum, cellValue) => {
	return cellValue.slice(0, 10);
};

//为主石重量加上单位
const mainweight = (row, colum, cellValue) => {
	if (cellValue) {
		return cellValue + row.MainStoneCategory_weightunit;
	} else {
		return cellValue;
	}
};
//为副石重量加上单位
const accessoryweight = (row, colum, cellValue) => {
	if (cellValue) {
		return cellValue + row.AccessorySoneCategory_weightunit;
	} else {
		return cellValue;
	}
};
//为总重加上单位
const totalweight = (row, colum, cellValue) => {
	if (cellValue) {
		return cellValue + row.GoodsCategory_weightunit;
	} else {
		return cellValue;
	}
};
//为金重加上单位
const goldweight = (row, colum, cellValue) => {
	if (cellValue) {
		return cellValue + 'g';
	} else {
		return cellValue;
	}
};
//进货日期选择时禁用今天之后的日期
const disabledDate = (time: Date) => {
	return time.getTime() > Date.now();
};

//主表某一行被点击
const rowclick = (row, column, event) => {
	if (column.id != 'el-table_1_column_1_column_12') {
		detaildrawer.value = true;
		detailtabledata.value = row.detail;
		billstate.value = row.PurchaseBill_state;
	}

	// console.log(detailtabledata.value);
};

//商品种类被选择后联动总重后面加上单位
const TotalWeightUnit = ref('');
const goodscategoryclick = (val) => {
	console.log(basics.goodcategory);
	console.log(val);

	basics.goodcategory.forEach((element) => {
		if (element.GoodsCategory_name == val) {
			TotalWeightUnit.value = element.GoodsCategory_weightunit;
		}
	});
};
//主石种类被选择后联动主石重量后面加上单位
const MSWeightUnit = ref('');
const MScategoryclick = (val) => {
	basics.stonecategory.forEach((element) => {
		if (element.StoneCategory_name == val) {
			MSWeightUnit.value = element.StoneCategory_weightunit;
		}
	});
};

//副石种类被选择后联动主石重量后面加上单位
const ASWeightUnit = ref('');
const AScategoryclick = (val) => {
	basics.stonecategory.forEach((element) => {
		if (element.StoneCategory_name == val) {
			ASWeightUnit.value = element.StoneCategory_weightunit;
		}
	});
};

//自动计算开关
const autochecked = ref();
//失去焦点时检测是否为数字
const RingSizeblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,3})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_RingSize = '';
	}
};

const TotalWeightblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,3})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_TotalWeight = '';
	}
};
//金重
const GoldWeightblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,3})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_GoldWeight = '';
	}

	CostCount();
};
//金成本
const CleanGoldPriceblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,2})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_CleanGoldPrice = '';
	}
};
//金价
const GoldPriceblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,2})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_GoldPrice = '';
	}

	CostCount();
};
//耗损
const WearRateblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,3})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_WearRate = '';
	}

	CostCount();
};
//主石重
const MainStoneWeightblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,3})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_MainStoneWeight = '';
	}

	CostCount();
};
//主石单价
const MinStonePriceblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,2})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_MinStonePrice = '';
	}

	CostCount();
};
//主石数量
const MinStoneQuantityblur = (value) => {
	let a = new RegExp('^[1-9]\\d*$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_MinStoneQuantity = '';
	}

	CostCount();
};
//石价计法
const MSPriceMethodblur = (value) => {
	CostCount();
};

//副石重
const AccessoryStoneWeightblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,3})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_AccessoryStoneWeight = '';
	}

	CostCount();
};
//副石价计法
const ASPriceMethodblur = (value) => {
	CostCount();
};

//副石单价
const AccessoryStonePriceblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,2})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_AccessoryStonePrice = '';
	}

	CostCount();
};
//副石数量
const AccessoryStoneQuantityblur = (value) => {
	let a = new RegExp('^[1-9]\\d*$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_AccessoryStoneQuantity = '';
	}

	CostCount();
};
//工费计法
const CostMethodblur = (value) => {
	CostCount();
};
//其他费
const OtherCostblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,2})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_OtherCost = '';
	}

	CostCount();
};
//加工费
const ProcessCostblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,2})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_ProcessCost = '';
	}

	CostCount();
};
//证书费
const CertificateCostblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,2})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_CertificateCost = '';
	}

	CostCount();
};
//销售倍率
const SalesRatioblur = (value) => {
	let a = new RegExp('^([1-9][0-9]*)+(\\.[0-9]{1,2})?$');
	if (value.match(a) == null) {
		detailform.PurchaseDetailBill_SalesRatio = '';
	}

	CostCount();
};
//成本价格计算公式
const CostCount = () => {
	if (autochecked.value == 1) {
		let CleanGoldPrice = Number(detailform.PurchaseDetailBill_CleanGoldPrice); //金成本
		let GoldWeight = Number(detailform.PurchaseDetailBill_GoldWeight); //金重
		let GoldPrice = Number(detailform.PurchaseDetailBill_GoldPrice); //金价
		let WearRate = Number(detailform.PurchaseDetailBill_WearRate); //耗损

		CleanGoldPrice = Math.floor((GoldWeight + WearRate) * GoldPrice * 100) / 100;

		detailform.PurchaseDetailBill_CleanGoldPrice = CleanGoldPrice + '' == '0' ? '' : CleanGoldPrice + ''; //金成本计算

		//主石价格计算
		let MinStoneQuantity = Number(detailform.PurchaseDetailBill_MinStoneQuantity); //主石数量
		let MainStoneWeight = Number(detailform.PurchaseDetailBill_MainStoneWeight); //主石重
		let MinStonePrice = Number(detailform.PurchaseDetailBill_MinStonePrice); //主石单价
		let MainStoneTotalPrice = Number(detailform.PurchaseDetailBill_MainStoneTotalPrice); //主石总价

		if (detailform.PurchaseDetailBill_MSPriceMethod == '1') {
			//计件
			MainStoneTotalPrice = 0;
			MainStoneTotalPrice = Math.floor(MinStonePrice * MinStoneQuantity * 100) / 100;
			detailform.PurchaseDetailBill_MainStoneTotalPrice = MainStoneTotalPrice + '' == '0' ? '' : MainStoneTotalPrice + '';
		}

		if (detailform.PurchaseDetailBill_MSPriceMethod == '2') {
			//计重
			MainStoneTotalPrice = 0;
			MainStoneTotalPrice = Math.floor(MinStonePrice * MainStoneWeight * 100) / 100;
			detailform.PurchaseDetailBill_MainStoneTotalPrice = MainStoneTotalPrice + '' == '0' ? '' : MainStoneTotalPrice + '';
		}

		//副石价格计算
		let AccessoryStoneQuantity = Number(detailform.PurchaseDetailBill_AccessoryStoneQuantity); //副石数量
		let AccessoryStoneWeight = Number(detailform.PurchaseDetailBill_AccessoryStoneWeight); //副石重
		let AccessoryStonePrice = Number(detailform.PurchaseDetailBill_AccessoryStonePrice); //副石单价
		let AccessoryStoneTotalPrice = Number(detailform.PurchaseDetailBill_AccessoryStoneTotalPrice); //副石总价

		if (detailform.PurchaseDetailBill_ASPriceMethod == '1') {
			//计件
			AccessoryStoneTotalPrice = 0;
			AccessoryStoneTotalPrice = Math.floor(AccessoryStonePrice * AccessoryStoneQuantity * 100) / 100;
			detailform.PurchaseDetailBill_AccessoryStoneTotalPrice = AccessoryStoneTotalPrice + '' == '0' ? '' : AccessoryStoneTotalPrice + '';
		}

		if (detailform.PurchaseDetailBill_ASPriceMethod == '2') {
			//计重
			AccessoryStoneTotalPrice = 0;
			AccessoryStoneTotalPrice = Math.floor(AccessoryStonePrice * AccessoryStoneWeight * 100) / 100;
			detailform.PurchaseDetailBill_AccessoryStoneTotalPrice = AccessoryStoneTotalPrice + '' == '0' ? '' : AccessoryStoneTotalPrice + '';
		}

		//成本计算
		let ProcessCost = Number(detailform.PurchaseDetailBill_ProcessCost); //加工费
		let CertificateCost = Number(detailform.PurchaseDetailBill_CertificateCost); //证书费
		let OtherCost = Number(detailform.PurchaseDetailBill_OtherCost); //其他费
		let cost = Number(detailform.PurchaseDetailBill_cost); //成本

		cost = Math.floor((ProcessCost + CertificateCost + OtherCost + AccessoryStoneTotalPrice + MainStoneTotalPrice + CleanGoldPrice) * 100) / 100;
		detailform.PurchaseDetailBill_cost = cost + '' == '0' ? '' : cost + '';

		//销售价计算
		let SalesPrice = Number(detailform.PurchaseDetailBill_SalesPrice); //销售总价
		let SalesRatio = Number(detailform.PurchaseDetailBill_SalesRatio); //销售倍率
		SalesPrice = Math.floor(SalesRatio * cost * 100) / 100;
		detailform.PurchaseDetailBill_SalesPrice = SalesPrice + '' == '0' ? '' : SalesPrice + '';
	}
};

//点击新增明细表确认按钮
const submitdetailform = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.validate((valid) => {
		if (valid) {
			Setdetailtabledata.value.push(JSON.parse(JSON.stringify(detailform))); //深拷贝detailform,这是要上传到后台的数据
			Setdetailtabledata_data.value.push(JSON.parse(JSON.stringify(detailform))); //先把所有数据拷贝到Setdetailtabledata_data
			console.log(detailform['PurchaseDetailBill_AccessoryCategory_id']);

			//把id转换为name给表格绑定的数组Setdetailtabledata_data
			basics.stonecategory.find((item) => {
				if (item.StoneCategory_id == detailform['PurchaseDetailBill_AccessoryCategory_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_AccessoryCategory_name'] = item.StoneCategory_name;
				}
			});

			basics.goodsbrand.find((item) => {
				if (item.GoodsBrand_id == detailform['PurchaseDetailBill_GoodsBrand_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_GoodsBrand_name'] = item.GoodsBrand_name;
				}
			});

			basics.goodcategory.find((item) => {
				if (item.GoodsCategory_id == detailform['PurchaseDetailBill_GoodsCategory_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_GoodsCategory_name'] = item.GoodsCategory_name;
				}
			});

			basics.goodsgrade.find((item) => {
				if (item.GoodsGrade_id == detailform['PurchaseDetailBill_GoodsGrade_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_GoodsGrade_name'] = item.GoodsGrade_name;
				}
			});

			basics.goodsseries.find((item) => {
				if (item.GoodsSeries_id == detailform['PurchaseDetailBill_GoodsSeries_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_GoodsSeries_name'] = item.GoodsSeries_name;
				}
			});

			basics.stonecategory.find((item) => {
				if (item.StoneCategory_id == detailform['PurchaseDetailBill_MainStoneCategory_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_MainStoneCategory_name'] = item.StoneCategory_name;
				}
			});

			basics.stoneclarity.find((item) => {
				if (item.StoneClarity_id == detailform['PurchaseDetailBill_StoneClarity_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_StoneClarity_name'] = item.StoneClarity_name;
				}
			});

			basics.stonecolor.find((item) => {
				if (item.StoneColor_id == detailform['PurchaseDetailBill_StoneColor_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_StoneColor_name'] = item.StoneColor_name;
				}
			});

			basics.stonecut.find((item) => {
				if (item.StoneCut_id == detailform['PurchaseDetailBill_StoneCut_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_StoneCut_name'] = item.StoneCut_name;
				}
			});

			basics.stoneinlay.find((item) => {
				if (item.StoneInlay_id == detailform['PurchaseDetailBill_StoneInlay_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_StoneInlay_name'] = item.StoneInlay_name;
				}
			});

			basics.stoneshape.find((item) => {
				if (item.StoneShape_id == detailform['PurchaseDetailBill_StoneShape_id']) {
					Setdetailtabledata_data.value[Setdetailtabledata_data.value.length - 1]['PurchaseDetailBill_StoneShape_name'] = item.StoneShape_name;
				}
			});

			console.log(Setdetailtabledata_data.value);

			ElMessage.success('添加成功');
		} else {
			console.log('验证失败');
			return false;
		}
	});
};

//新增明细表里的删除按钮
const inster_delclick = (val) => {
	console.log(val.$index);
	Setdetailtabledata_data.value.splice(val.$index, 1);
	Setdetailtabledata.value.splice(val.$index, 1);
};

//添加进货单确认按钮
const insertPurchaseBill = async (PurchaseDetailBilldata) => {
	// let data = [];

	// data['PurchaseBill'] = mainform;
	// data['PurchaseDetailBill'] = Setdetailtabledata.value;
	//判断Setdetailtabledata是否为空，为空则不让添加
	if (Setdetailtabledata.value.length <= 0) {
		ElMessage.error('商品信息为空，请添加商品');
		return false;
	}

	const { data } = await Add_PurchaseBill(mainform, filterEmptyValues(Setdetailtabledata.value));
	if (data.code == 200) {
		ElMessage.success('添加成功');
		Setdetailtabledata_data.value = [];
		Setdetailtabledata.value = [];
		refreshtable(currentPage.value, pageSize.value);
		maindrawer.value = false;
	} else {
		ElMessage.error(data.msg);
	}
};
//新增表单的明细表表格上传到后台数据
const Setdetailtabledata = ref([]);
//新增的明细表格表格展示
const Setdetailtabledata_data = ref([]);

const tableData = [
	{
		date: '2016-05-03',
		name: 'Tom',
		address: 'No. 189, Grove St, Los Angeles',
	},
	{
		date: '2016-05-02',
		name: 'Tom',
		address: 'No. 189, Grove St, Los Angeles',
	},
	{
		date: '2016-05-04',
		name: 'Tom',
		address: 'No. 189, Grove St, Los Angeles',
	},
	{
		date: '2016-05-01',
		name: 'Tom',
		address: 'No. 189, Grove St, Los Angeles',
	},
];

//筛选
//const state=ref(0);
const filterchange = async (column) => {
	//单据状态
	if (column['PurchaseBill_state']) {
		//把单据的状态给刷新函数
		state.value = column['PurchaseBill_state'][0];

		refreshtable(currentPage.value, pageSize.value);
	}

	//分店筛选
	if (column['PurchaseBill_branch']) {
		branchF.value = column['PurchaseBill_branch'][0];
		refreshtable(currentPage.value, pageSize.value);
	}
};

//处理excel导入
const fileList = ref<any[]>([]);
//需要添加的基础资料,弹出框表格绑定对象
const miss_basicdata_table = ref([]);
//需要添加基础资料的弹出框绑定对象
const miss_basicdatatable_drawer = ref(false);
//新增基础资料条数
const miss_basicdata_count = ref(0);

const handleBeforeUpload = (file: File) => {
	const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || file.type === 'application/vnd.ms-excel';
	if (!isExcel) {
		ElMessage.error('上传文件只能是 Excel 格式!');
		return false;
	}
	const reader = new FileReader();
	reader.onload = async (e: any) => {
		const data = new Uint8Array(e.target.result);
		const workbook = XLSX.read(data, { type: 'array' });
		const sheetName = workbook.SheetNames[0]; // 假设只有第一个工作表
		const worksheet = workbook.Sheets[sheetName];
		const jsonData = XLSX.utils.sheet_to_json(worksheet);
		// 这里处理你的 jsonData，比如发送到后端等

		// 定义模板规则
		const templateRules = {
			// 示例规则，实际使用时需要根据你的模板来定义
			columns: [
				{ name: '商品名称', required: true },
				{ name: '商品种类', required: true },
				{ name: '销售价', required: true },
				{ name: '手寸', type: 'number' },
				{ name: '总重', type: 'number' },
				{ name: '金重', type: 'number' },
				{ name: '金价', type: 'number' },
				{ name: '耗损', type: 'number' },
				{ name: '金成本', type: 'number' },
				{ name: '主石数量', type: 'number' },
				{ name: '主石重', type: 'number' },
				{ name: '主石单价', type: 'number' },
				{ name: '主石价格', type: 'number' },
				{ name: '副石数量', type: 'number' },
				{ name: '副石重', type: 'number' },
				{ name: '副石单价', type: 'number' },
				{ name: '副石价格', type: 'number' },
				{ name: '加工费', type: 'number' },
				{ name: '证书费', type: 'number' },
				{ name: '其他费', type: 'number' },
				{ name: '成本', type: 'number' },
				{ name: '销售倍率', type: 'number' },
				{ name: '销售价', type: 'number' },
				{ name: '计价方式', enum: true, required: true },
				{ name: '副石计法', enum: true },
				{ name: '工费计法', enum: true },

				// ... 其他列规则
			],
		};

		// 校验数据是否符合模板规则
		if (!validateData(jsonData, templateRules)) {
			//ElMessage.error('上传的文件不符合模板要求！');
			return false;
		}

		// 定义表头到字段的映射
		const headerToFieldMapping = {
			商品品牌: 'PurchaseDetailBill_GoodsBrand_name',
			商品成色: 'PurchaseDetailBill_GoodsGrade_name',
			商品系列: 'PurchaseDetailBill_GoodsSeries_name',
			商品种类: 'PurchaseDetailBill_GoodsCategory_name',
			商品款号: 'PurchaseDetailBill_StyleNumber',
			商品名称: 'PurchaseDetailBill_name',
			证书号: 'PurchaseDetailBill_CertificateNo',
			原编号: 'PurchaseDetailBill_OriginalNumber',
			计价方式: 'PurchaseDetailBill_PriceMethod',
			手寸: 'PurchaseDetailBill_RingSize',
			总重: 'PurchaseDetailBill_TotalWeight',
			金重: 'PurchaseDetailBill_GoldWeight',
			金价: 'PurchaseDetailBill_GoldPrice',
			耗损: 'PurchaseDetailBill_WearRate',
			金成本: 'PurchaseDetailBill_CleanGoldPrice',
			宝石镶法: 'PurchaseDetailBill_StoneInlay_name',
			宝石形状: 'PurchaseDetailBill_StoneShape_name',
			宝石颜色: 'PurchaseDetailBill_StoneColor_name',
			宝石净度: 'PurchaseDetailBill_StoneClarity_name',
			宝石车工: 'PurchaseDetailBill_StoneCut_name',
			主石类别: 'PurchaseDetailBill_MainStoneCategory_name',
			主石计法: 'PurchaseDetailBill_MSPriceMethod',
			主石数量: 'PurchaseDetailBill_MinStoneQuantity',
			主石重: 'PurchaseDetailBill_MainStoneWeight',
			主石单价: 'PurchaseDetailBill_MinStonePrice',
			主石价格: 'PurchaseDetailBill_MainStoneTotalPrice',
			副石类别: 'PurchaseDetailBill_AccessoryCategory_name',
			副石计法: 'PurchaseDetailBill_ASPriceMethod',
			副石数量: 'PurchaseDetailBill_AccessoryStoneQuantity',
			副石重: 'PurchaseDetailBill_AccessoryStoneWeight',
			副石单价: 'PurchaseDetailBill_AccessoryStonePrice',
			副石价格: 'PurchaseDetailBill_AccessoryStoneTotalPrice',
			工费计法: 'PurchaseDetailBill_CostMethod',
			加工费: 'PurchaseDetailBill_ProcessCost',
			证书费: 'PurchaseDetailBill_CertificateCost',
			其他费: 'PurchaseDetailBill_OtherCost',
			成本: 'PurchaseDetailBill_cost',
			销售倍率: 'PurchaseDetailBill_SalesRatio',
			销售价: 'PurchaseDetailBill_SalesPrice',
		};

		// 转换数据
		const convertedData = jsonData.map((row) => {
			const convertedRow = {};
			for (const key in row) {
				if (headerToFieldMapping[key]) {
					convertedRow[headerToFieldMapping[key]] = row[key];
				}
			}
			return convertedRow;
		});

		//检查基础资料,如果发现不存在的基础资料则提示用户去添加
		const { data: infodata } = await checkImportData(jsonData);
		if (infodata.code == 200) {
			if (infodata.data.length > 0) {
				//存在不匹配的基础资料,提示用户去添加
				miss_basicdatatable_drawer.value = true;
				miss_basicdata_table.value = infodata.data;
				miss_basicdata_count.value = infodata.data.length;
			} else {
				Setdetailtabledata_data.value = convertedData;
				//请求后台把name转换成id,
				const { data: conversiondata } = await Get_IdByFieldAndValue(Setdetailtabledata_data.value);

				if (conversiondata.code == 200) {
					Setdetailtabledata.value = conversiondata.data;
					console.log(Setdetailtabledata.value);
				} else {
					ElMessage.error(conversiondata.msg);
					return false;
				}
			}
		} else {
			ElMessage.error(infodata.msg);
			return false;
		}

		console.log(infodata);

		//console.log(convertedData);
		//把数据赋值给表格绑定的数组
		Setdetailtabledata_data.value = convertedData;

		//console.log(convertedData);
	};
	reader.readAsArrayBuffer(file);
	return false; // 阻止自动上传
};

const handleSuccess = (response: any, file: File, fileList: any[]) => {
	// 这里处理上传成功后的逻辑，但因为我们手动处理文件，所以这个方法不会被调用
};

//重置新增表格里的数据
const resetmaindrawer = () => {
	Setdetailtabledata_data.value = [];
};

//新增基础资料取消按钮
const cancelmissbasicdata = () => {
	miss_basicdatatable_drawer.value = false;
	Setdetailtabledata_data.value = [];
};

//新增基础资料弹窗关闭前回调
const basicsbeforeclose = () => {
	miss_basicdatatable_drawer.value = false;
	Setdetailtabledata_data.value = [];
	return true;
};
//添加新增的基础资料
const addbascdata = async () => {
	const { data } = await Add_basicsinfo(miss_basicdata_table.value);
	if (data.code == 200) {
		ElMessage.success('新增成功');

		//请求后台把name转换成id,
		const { data: conversiondata } = await Get_IdByFieldAndValue(Setdetailtabledata_data.value);

		if (conversiondata.code == 200) {
			Setdetailtabledata.value = conversiondata.data;
			console.log(Setdetailtabledata.value);
		} else {
			ElMessage.error(conversiondata.msg);
			return false;
		}

		miss_basicdatatable_drawer.value = false;
	} else {
		ElMessage.error(data.msg);
	}
};

//确认单据
const Confirmdocuments = async (scope) => {
	//console.log(scope.PurchaseBill_id);
	const { data } = await Confirm_PurchaseBill(scope.PurchaseBill_id);
	if (data.code == 200) {
		ElMessage.success('确认成功');
		refreshtable(currentPage.value, pageSize.value);
	} else {
		ElMessage.error(data.msg);
	}
};

//作废单据
const voiddocuments = async (scope) => {
	const { data } = await Cancel_PurchaseBill(scope.PurchaseBill_id);
	if (data.code == 200) {
		ElMessage.success('作废成功');
		refreshtable(currentPage.value, pageSize.value);
	} else {
		ElMessage.error(data.msg);
	}
};

//删除进货单
const deletepurchase = async (scope) => {
	const { data } = await delete_purchasebillinfo(scope.PurchaseBill_id);
	if (data.code == 200) {
		ElMessage.success('删除成功');
		refreshtable(currentPage.value, pageSize.value);
	} else {
		ElMessage.error(data.msg);
	}
};

//查询按钮
const startDate = ref(undefined);
const endDate = ref(undefined);

const searchbtn = async () => {
	fetchPurchaseBillInfo();
};

//定义修改标志
const modifyflag = ref(false);
const tableRowEditId = ref(null); // 控制可编辑的每一行
const updatetext = ref('修改'); //定义修改的文字
//未确认状态的行,点击修改按钮
const updateurchaseBill = async (scope) => {
	tableRowEditId.value = scope.PurchaseBill_id;
	updatemainform.PurchaseBill_PurchaseDate = scope.PurchaseBill_PurchaseDate; //进货单日期默认值
	updatemainform.PurchaseBill_supplier_id = scope.PurchaseBill_supplier_id; //供应商默认id
	updatemainform.PurchaseBill_branch_id = scope.PurchaseBill_branch_id; //分店默认id
	updatemainform.PurchaseBill_remark = scope.PurchaseBill_remark; //默认备注
	console.log(scope.PurchaseBill_id);
	modifyflag.value = true;
};
//未确认状态的行,点击保存按钮
const updateurchaseBill_save = async (scope) => {
	tableRowEditId.value = null;

	//console.log(scope);
	//要修改的和原始的数据不一致则修改否则不修改
	if (scope.PurchaseBill_PurchaseDate !== updatemainform.PurchaseBill_PurchaseDate || scope.PurchaseBill_branch_id !== updatemainform.PurchaseBill_branch_id || scope.PurchaseBill_supplier_id !== updatemainform.PurchaseBill_supplier_id || scope.PurchaseBill_remark !== updatemainform.PurchaseBill_remark) {
		const { data } = await update_purchasebillinfo(scope.PurchaseBill_id, updatemainform);
		if (data.code == 200) {
			ElMessage.success('修改成功');
			fetchPurchaseBillInfo();
			updatemainform.PurchaseBill_PurchaseDate = undefined;
			updatemainform.PurchaseBill_branch_id = undefined;
			updatemainform.PurchaseBill_supplier_id = undefined;
			updatemainform.PurchaseBill_remark = '';
		} else {
			ElMessage.error(data.msg);
		}
	}
};

//定义明细表被修改的标志
const tableRowEditId_detail = ref(null); // 控制可编辑的每一行
//明细表内，未确认状态的行,点击修改按钮
const updatedetail = async (scope) => {
	tableRowEditId_detail.value = scope.PurchaseDetailBill_id;
	Object.assign(updatedetailform, scope); //复制整个对象属性
	console.log(scope);
};
//明细表内，未确认状态的行,点击保存按钮
const updatedetail_save = async (scope) => {
	console.log(tabledata);
	tableRowEditId_detail.value = null;
	if (!Object.entries(scope).every(([key, value]) => value === updatedetailform[key])) {
		const { data } = await update_PurchaseDetailinfo(scope.PurchaseDetailBill_id, updatedetailform);
		if (data.code == 200) {
			ElMessage.success('修改成功');
			fetchPurchaseBillInfo();
			detailtabledata.value = data.data;
		}
	} else {
		console.log('所有属性都相同');
	}
};

//删除明细表行
const deletedetail = async (scope) => {
	const { data } = await delete_PurchaseDetailinfo(scope.PurchaseDetailBill_id);
	if (data.code == 200) {
		ElMessage.success('删除成功');
		fetchPurchaseBillInfo();
		detailtabledata.value = data.data;
	} else {
		ElMessage.error(data.msg);
	}
};
//私有函数 查询获取进货单信息
async function fetchPurchaseBillInfo() {
	try {
		// 在函数内部明确初始化startDate和endDate为undefined
		startDate.value = undefined;
		endDate.value = undefined;

		// 检查roleseachform.productiondate是否是一个数组，并且有足够的元素
		if (Array.isArray(roleseachform.productiondate)) {
			startDate.value = roleseachform.productiondate[0] || undefined;
		}
		if (Array.isArray(roleseachform.productiondate)) {
			endDate.value = roleseachform.productiondate[1] || undefined;
		}

		loading.value = true;
		// 现在调用函数，startDate和endDate将会是undefined或者正确的值
		const { data } = await get_purchasebillinfo(currentPage.value, pageSize.value, startDate.value, endDate.value, roleseachform.billnumber, state.value, branchF.value);
		if (data.code == 200) {
			total.value = data.data.total;
			tabledata.value = data.data.data;
		} else {
			ElMessage.error(data.msg);
		}
		loading.value = false;

		// 使用返回的数据...
		console.log(data);
	} catch (error) {
		// 处理错误...
		console.error('获取采购单信息时出错:', error);
	}
}
</script>

<template>
	<div class="el-card_body">
		<el-form class="roleformclass" :inline="true" :model="roleseachform" label-width="80px">
			<el-form-item label="进货单号:">
				<el-input v-model="roleseachform.billnumber" placeholder="可省略JH模糊查询" clearable>
					<!-- <template #prepend>JH</template> -->
				</el-input>
			</el-form-item>
			<el-form-item label="制单日期:">
				<el-date-picker v-model="roleseachform.productiondate" type="daterange" range-separator="到"
					start-placeholder="开始时间" end-placeholder="结束时间" :size="size" value-format="YYYY-MM-DD 00:00:00" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="searchbtn">
					<el-icon style="vertical-align: middle">
						<Search />
					</el-icon>
					<span style="vertical-align: middle"> 查询 </span>
				</el-button>
				<!-- <el-button>重置</el-button> -->
			</el-form-item>
		</el-form>

		<el-table @filter-change="filterchange" :header-cell-style="{ background: '#f6f8f9', color: '#000000' }"
			v-loading="loading" ref="tableRef" :data="tabledata" height="calc(100vh - 300px)" style="width: 100%"
			highlight-current-row @cell-dblclick="rowclick">
			<el-table-column label="Address Info">
				<template #header>
					<div class="ele-table-tool ele-table-tool-default">
						<el-button type="primary" :icon="Plus" @click="
							maindrawer = true;
						dialogtype = 0;
						">添加</el-button>

						<div class="ele-tool">
							<el-tooltip effect="dark" content="刷新" placement="top">
								<el-button size="small" @click="refreshtable(currentPage, pageSize)"
									:icon="Refresh"></el-button>
							</el-tooltip>
							<el-tooltip effect="dark" content="列设置" placement="top">
								<el-button size="small" :icon="Setting"></el-button>
							</el-tooltip>
						</div>
					</div>
				</template>
				<el-table-column align="center" type="index" width="50" />
				<el-table-column prop="PurchaseBill_BillNumber" label="进货单号" align="center">
					<template #default="scope">
						<el-link type="primary">{{ scope.row.PurchaseBill_BillNumber }}</el-link>
					</template>
				</el-table-column>
				<el-table-column :filters="[
					{ text: '未确认', value: '未确认' },
					{ text: '已确认', value: '已确认' },
					{ text: '已作废', value: '已作废' },
				]" column-key="PurchaseBill_state" prop="PurchaseBill_state" label="状态" width="100" align="center"
					:filter-multiple="false">
					<template #default="scope">
						<el-tag v-if="scope.row.PurchaseBill_state == '未确认'"> {{ scope.row.PurchaseBill_state }}
						</el-tag>
						<el-tag type="success" v-if="scope.row.PurchaseBill_state == '已确认'"> {{
							scope.row.PurchaseBill_state }} </el-tag>
						<el-tag type="info" v-if="scope.row.PurchaseBill_state == '已作废'"> {{
							scope.row.PurchaseBill_state }} </el-tag>
					</template>
				</el-table-column>

				<el-table-column prop="PurchaseBill_PurchaseDate" :formatter="formatterdate" label="进货日期"
					align="center">
					<template #default="scope">
						<el-date-picker v-if="scope.row.PurchaseBill_id == tableRowEditId"
							v-model="updatemainform.PurchaseBill_PurchaseDate" type="date" placeholder="进货日期"
							format="YYYY/MM/DD" value-format="YYYY/MM/DD" />
						<div v-else>{{ scope.row.PurchaseBill_PurchaseDate.substring(0, 10) }}</div>
					</template>
				</el-table-column>
				<!-- <el-table-column v-else prop="PurchaseBill_PurchaseDate" :formatter="formatterdate" label="进货日期" align="center" /> -->
				<el-table-column prop="PurchaseBill_quantity" label="数量" align="center" />
				<!-- <el-table-column prop="branch_name" column-key="PurchaseBill_branch" :filters="branchArr"
					:filter-multiple="false" label="分店" align="center" /> -->
				<el-table-column prop="branch_name" column-key="PurchaseBill_branch" :filters="branchArr"
					:filter-multiple="false" label="分店" align="center">
					<template #default="scope">
						<el-select v-if="scope.row.PurchaseBill_id == tableRowEditId"
							v-model="updatemainform.PurchaseBill_branch_id" placeholder="请选择分店">
							<el-option v-for="item in basics.branch" :key="item.branch_id" :label="item.branch_name"
								:value="item.branch_id" />
						</el-select>
						<div v-else>{{ scope.row.branch_name }}</div>
					</template>
				</el-table-column>
				<!-- <el-table-column prop="supplier_name" label="供应商" align="center" /> -->
				<el-table-column prop="supplier_name" label="供应商" align="center">
					<template #default="scope">
						<el-select v-if="scope.row.PurchaseBill_id == tableRowEditId"
							v-model="updatemainform.PurchaseBill_supplier_id" placeholder="请选择供应商">
							<el-option v-for="item in basics.supplier" :key="item.supplier_id"
								:label="item.supplier_name" :value="item.supplier_id" />
						</el-select>
						<div v-else>{{ scope.row.supplier_name }}</div>
					</template>
				</el-table-column>

				<el-table-column prop="user_name" label="制单人" align="center" />
				<el-table-column prop="PurchaseBill_creationtime" :formatter="formatterdate" label="制单日期"
					align="center" />
				<!-- <el-table-column prop="PurchaseBill_remark" label="备注" align="center" /> -->
				<el-table-column prop="PurchaseBill_remark" label="备注" align="center">
					<template #default="scope">
						<el-input v-if="scope.row.PurchaseBill_id == tableRowEditId"
							v-model="updatemainform.PurchaseBill_remark" />
						<div v-else>{{ scope.row.PurchaseBill_remark }}</div>
					</template>
				</el-table-column>
				<el-table-column fixed="right" align="center" label="操作" min-width="110">
					<template #default="scope">
						<el-popconfirm @confirm="Confirmdocuments(scope.row)" title="是否确认单据?此操作不可撤销"
							v-if="scope.row.PurchaseBill_state == '未确认'">
							<template #reference>
								<el-button type="text" :icon="Check">确认</el-button>
							</template>
						</el-popconfirm>
						<el-button type="text" @click="updateurchaseBill_save(scope.row)" :icon="EditPen"
							v-if="scope.row.PurchaseBill_state == '未确认' && scope.row.PurchaseBill_id == tableRowEditId">保存</el-button>
						<el-button type="text" @click="updateurchaseBill(scope.row)" :icon="EditPen"
							v-else-if="scope.row.PurchaseBill_state == '未确认'">修改</el-button>
						<el-popconfirm :icon="InfoFilled" confirm-button-text="作废" icon-color="red"
							confirmButtonType="danger" @confirm="voiddocuments(scope.row)" title="是否作废单据?"
							v-if="scope.row.PurchaseBill_state == '未确认'">
							<template #reference>
								<el-button class="operate" type="text" :icon="Delete">作废</el-button>
							</template>
						</el-popconfirm>
						<el-popconfirm :icon="InfoFilled" confirm-button-text="确认" icon-color="#e6a23c"
							confirmButtonType="warning" @confirm="delclick(scope.row)" title="是否生成采购退货单?"
							v-if="scope.row.PurchaseBill_state == '已确认'">
							<template #reference>
								<el-button class="operate2" type="text" :icon="Document">采购退货</el-button>
							</template>
						</el-popconfirm>
						<el-popconfirm :icon="InfoFilled" confirm-button-text="确认" icon-color="#red"
							confirmButtonType="info" @confirm="deletepurchase(scope.row)" title="是否删除单据?"
							v-if="scope.row.PurchaseBill_state == '已作废'">
							<template #reference>
								<el-button class="operate3" type="text" :icon="Delete">删除</el-button>
							</template>
						</el-popconfirm>
						<!-- <el-button type="text" class="reset" :icon="CopyDocument">重置密码</el-button> -->
					</template>
				</el-table-column>
			</el-table-column>
		</el-table>
		<!-- 分页 -->
		<div class="ele-pagination">
			<el-pagination v-model:currentPage="currentPage" :page-sizes="[10, 20, 30, 40]" background
				layout="total, sizes, prev, pager, next, jumper" :total="total"
				@update:current-page="handleCurrentChange" @update:page-size="handleSizeChange" />
		</div>
	</div>
	<!-- 新增主表和明细表-->
	<el-drawer size="679px" v-model="maindrawer" title="添加进货单">
		<el-divider style="margin-bottom: 40px" content-position="center">单据信息</el-divider>
		<el-form ref="mainformref" :model="mainform" label-width="85px">
			<el-row style="margin-left: -7.5px; margin-right: -7.5px">
				<el-col :span="24" :sm="12">
					<el-form-item label="分店:" prop="PurchaseBill_branch_id">
						<el-select v-model="mainform.PurchaseBill_branch_id" placeholder="请选择分店">
							<el-option v-for="item in basics.branch" :key="item.branch_id" :label="item.branch_name"
								:value="item.branch_id" />
						</el-select>
					</el-form-item>
					<el-form-item label="供应商:" prop="PurchaseBill_supplier_id">
						<el-select v-model="mainform.PurchaseBill_supplier_id" placeholder="请选择供应商">
							<el-option v-for="item in basics.supplier" :key="item.supplier_id"
								:label="item.supplier_name" :value="item.supplier_id" />
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" :sm="12">
					<el-form-item label="进货日期:" prop="PurchaseBill_PurchaseDate">
						<el-date-picker value-format="YYYY-MM-DD" v-model="mainform.PurchaseBill_PurchaseDate"
							:disabled-date="disabledDate" type="date" placeholder="请选择进货日期" />
					</el-form-item>
					<el-form-item label="备注:" prop="PurchaseBill_remark">
						<el-col :span="22">
							<el-input autosize v-model="mainform.PurchaseBill_remark" placeholder="请输入备注" />
						</el-col>
					</el-form-item>
				</el-col>
			</el-row>
			<el-divider style="margin-top: 40px" content-position="center">添加商品</el-divider>
			<el-card :body-style="{ padding: '0px', border: 'none' }" shadow="never" class="box-card">
				<template #header>
					<div class="card-header">
						<el-button type="primary" @click="detaildialog = true" :icon="Plus">添加</el-button>
						<el-upload class="upload_class" action="#" :before-upload="handleBeforeUpload"
							:on-success="handleSuccess" :file-list="fileList" :show-file-list="false">
							<el-button slot="trigger" type="success">excel导入</el-button>
						</el-upload>
					</div>
				</template>
				<el-table max-height="440" :data="Setdetailtabledata_data" border height="450px" style="width: 100%">
					<el-table-column fixed align="center" type="index" width="60" />
					<!-- <el-table-column fixed prop="PurchaseDetailBill_Barcode" label="条码" width="130" /> -->
					<el-table-column prop="PurchaseDetailBill_name" label="品名" width="120" />
					<el-table-column prop="PurchaseDetailBill_GoodsCategory_name" label="商品种类" width="90" />
					<el-table-column prop="PurchaseDetailBill_PriceMethod" label="计价方式" width="90" />
					<el-table-column prop="PurchaseDetailBill_GoodsGrade_name" label="商品成色" width="90" />
					<el-table-column prop="PurchaseDetailBill_GoodsSeries_name" label="商品系列" width="90" />
					<el-table-column prop="PurchaseDetailBill_GoodsBrand_name" label="商品品牌" width="90" />
					<el-table-column prop="PurchaseDetailBill_StyleNumber" label="款号" width="120" />
					<el-table-column prop="PurchaseDetailBill_CertificateNo" label="证书号" width="120" />
					<el-table-column prop="PurchaseDetailBill_OriginalNumber" label="原编码" width="120" />
					<el-table-column prop="PurchaseDetailBill_GoldWeight" :formatter="goldweight" label="金重"
						width="90" />
					<el-table-column prop="PurchaseDetailBill_WearRate" label="耗损" width="70" />
					<el-table-column prop="PurchaseDetailBill_CleanGoldPrice" label="金成本" width="70" />
					<el-table-column prop="PurchaseDetailBill_TotalWeight" label="总重" :formatter="totalweight"
						width="90" />
					<el-table-column prop="PurchaseDetailBill_RingSize" label="手寸" width="70" />
					<el-table-column prop="PurchaseDetailBill_MainStoneCategory_name" label="主石类别" width="90" />
					<el-table-column prop="PurchaseDetailBill_MainStoneWeight" :formatter="mainweight" label="主石重"
						width="90" />
					<el-table-column prop="PurchaseDetailBill_MinStoneQuantity" label="主石数量" width="90" />
					<el-table-column prop="PurchaseDetailBill_MSPriceMethod" label="主石计法" width="100" />
					<el-table-column prop="PurchaseDetailBill_MinStonePrice" label="主石单价" width="100" />
					<el-table-column prop="PurchaseDetailBill_MainStoneTotalPrice" label="主石价格" width="100" />
					<el-table-column prop="PurchaseDetailBill_AccessoryCategory_name" label="副石类别" width="90" />
					<el-table-column prop="PurchaseDetailBill_AccessoryStoneWeight" :formatter="accessoryweight"
						label="副石重" width="100" />
					<el-table-column prop="PurchaseDetailBill_AccessoryStoneQuantity" label="副石数量" width="90" />
					<el-table-column prop="PurchaseDetailBill_ASPriceMethod" label="副石计法" width="100" />
					<el-table-column prop="PurchaseDetailBill_AccessoryStonePrice" label="副石单价" width="100" />
					<el-table-column prop="PurchaseDetailBill_AccessoryStoneTotalPrice" label="副石价格" width="100" />
					<el-table-column prop="PurchaseDetailBill_StoneInlay_name" label="镶法" width="90" />
					<el-table-column prop="PurchaseDetailBill_StoneShape_name" label="形状" width="90" />
					<el-table-column prop="PurchaseDetailBill_StoneColor_name" label="颜色" width="90" />
					<el-table-column prop="PurchaseDetailBill_StoneClarity_name" label="净度" width="90" />
					<el-table-column prop="PurchaseDetailBill_StoneCut_name" label="车工" width="90" />
					<el-table-column prop="PurchaseDetailBill_ProcessCost" label="加工费" width="100" />
					<el-table-column prop="PurchaseDetailBill_CertificateCost" label="证书费" width="100" />
					<el-table-column prop="PurchaseDetailBill_OtherCost" label="其他费" width="100" />
					<el-table-column prop="PurchaseDetailBill_cost" label="成本" width="100" />
					<el-table-column prop="PurchaseDetailBill_SalesRatio" label="销售倍率" width="90" />
					<el-table-column prop="PurchaseDetailBill_SalesPrice" label="销售总价" width="100" />
					<el-table-column fixed="right" align="center" label="操作" width="80">
						<template #default="scope">
							<el-popconfirm @confirm="inster_delclick(scope)" title="是否确认删除?">
								<template #reference>
									<el-button class="operate" type="text" :icon="Delete">删除</el-button>
								</template>
							</el-popconfirm>
							<!-- <el-button type="text" class="reset" :icon="CopyDocument">重置密码</el-button> -->
						</template>
					</el-table-column>
				</el-table>
			</el-card>
		</el-form>
		<template #footer>
			<div style="flex: auto">
				<el-button @click="resetmaindrawer">重置</el-button>
				<el-button type="primary" @click="insertPurchaseBill(Setdetailtabledata)">保存</el-button>
			</div>
		</template>
	</el-drawer>
	<!-- 查看明细表 -->
	<el-drawer size="40%" v-model="detaildrawer" title="进货单明细" direction="btt">
		<el-table :header-cell-style="{ background: '#f6f8f9', color: '#000000' }" border :data="detailtabledata"
			height="25vh" style="width: 100%">
			<!-- <el-table-column fixed prop="PurchaseDetailBill_PurchaseBill_BillNumber" label="进货单号" width="120" /> -->
			<el-table-column fixed align="center" type="index" width="60" />
			<el-table-column fixed prop="PurchaseDetailBill_Barcode" label="条码" width="130" align="center" />
			<!-- <el-table-column prop="PurchaseDetailBill_name" label="商品名称" width="120" /> -->
			<el-table-column prop="PurchaseDetailBill_name" label="商品名称" width="120" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						v-model="updatedetailform.PurchaseDetailBill_name" />
					<div v-else>{{ scope.row.PurchaseDetailBill_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_GoodsCategory_name" label="商品种类" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_GoodsCategory_name" label="商品种类" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						v-model="updatedetailform.PurchaseDetailBill_GoodsCategory_id" placeholder="商品种类">
						<el-option v-for="item in basics.goodcategory" :key="item.GoodsCategory_id"
							:label="item.GoodsCategory_name" :value="item.GoodsCategory_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_GoodsCategory_name }}</div>
				</template>
			</el-table-column>

			<!-- <el-table-column prop="PurchaseDetailBill_PriceMethod" label="计价方式" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_PriceMethod" label="计价方式" width="120" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						v-model="updatedetailform.PurchaseDetailBill_PriceMethod" placeholder="请选择计价方式">
						<el-option key="1" label="计件" value="计件" />
						<el-option key="2" label="计重" value="计重" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_PriceMethod }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_GoodsGrade_name" label="商品成色" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_GoodsGrade_name" label="商品成色" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_GoodsGrade_id" placeholder="请选择成色">
						<el-option v-for="item in basics.goodsgrade" :key="item.GoodsGrade_id"
							:label="item.GoodsGrade_name" :value="item.GoodsGrade_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_GoodsGrade_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_GoodsSeries_name" label="商品系列" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_GoodsSeries_name" label="商品系列" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_GoodsSeries_id" placeholder="请选择系列">
						<el-option v-for="item in basics.goodsseries" :key="item.GoodsSeries_id"
							:label="item.GoodsSeries_name" :value="item.GoodsSeries_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_GoodsSeries_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_GoodsBrand_name" label="商品品牌" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_GoodsBrand_name" label="商品品牌" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_GoodsBrand_id" placeholder="请选择品牌">
						<el-option v-for="item in basics.goodsbrand" :key="item.GoodsBrand_id"
							:label="item.GoodsBrand_name" :value="item.GoodsBrand_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_GoodsBrand_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_StyleNumber" label="款号" width="120" /> -->
			<el-table-column prop="PurchaseDetailBill_StyleNumber" label="款号" width="120" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						v-model="updatedetailform.PurchaseDetailBill_StyleNumber" />
					<div v-else>{{ scope.row.PurchaseDetailBill_StyleNumber }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_CertificateNo" label="证书号" width="120" /> -->
			<el-table-column prop="PurchaseDetailBill_CertificateNo" label="证书号" width="120" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						v-model="updatedetailform.PurchaseDetailBill_CertificateNo" />
					<div v-else>{{ scope.row.PurchaseDetailBill_CertificateNo }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_OriginalNumber" label="原编码" width="120" /> -->
			<el-table-column prop="PurchaseDetailBill_OriginalNumber" label="原编码" width="120" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						v-model="updatedetailform.PurchaseDetailBill_OriginalNumber" />
					<div v-else>{{ scope.row.PurchaseDetailBill_OriginalNumber }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_GoldWeight" :formatter="goldweight" label="金重" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_GoldWeight" :formatter="goldweight" label="金重" width="90"
				align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_GoldWeight" />
					<div v-else>{{ scope.row.PurchaseDetailBill_GoldWeight }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_WearRate" label="耗损" width="70" /> -->
			<el-table-column prop="PurchaseDetailBill_WearRate" label="耗损" width="70" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_WearRate" />
					<div v-else>{{ scope.row.PurchaseDetailBill_WearRate }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_CleanGoldPrice" label="金成本" width="70" /> -->
			<el-table-column prop="PurchaseDetailBill_CleanGoldPrice" label="金成本" width="70" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_CleanGoldPrice" />
					<div v-else>{{ scope.row.PurchaseDetailBill_CleanGoldPrice }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_TotalWeight" label="总重" :formatter="totalweight" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_TotalWeight" label="总重" :formatter="totalweight" width="90"
				align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_TotalWeight" />
					<div v-else>{{ scope.row.PurchaseDetailBill_TotalWeight }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_RingSize" label="手寸" width="70" /> -->
			<el-table-column prop="PurchaseDetailBill_RingSize" label="手寸" width="70" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_RingSize" />
					<div v-else>{{ scope.row.PurchaseDetailBill_RingSize }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_MainStoneCategory_name" label="主石类别" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_MainStoneCategory_name" label="主石类别" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" @change="MScategoryclick"
						clearable v-model="updatedetailform.PurchaseDetailBill_MainStoneCategory_id"
						placeholder="请选择主石类别">
						<el-option v-for="item in basics.stonecategory" :key="item.StoneCategory_id"
							:label="item.StoneCategory_name" :value="item.StoneCategory_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_MainStoneCategory_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_MainStoneWeight" :formatter="mainweight" label="主石重" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_MainStoneWeight" :formatter="mainweight" label="主石重" width="90"
				align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_MainStoneWeight" />
					<div v-else>{{ scope.row.PurchaseDetailBill_MainStoneWeight }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_MinStoneQuantity" label="主石数量" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_MinStoneQuantity" label="主石数量" width="90" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d]/g, '')"
						v-model="updatedetailform.PurchaseDetailBill_MinStoneQuantity" />
					<div v-else>{{ scope.row.PurchaseDetailBill_MinStoneQuantity }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_MSPriceMethod" label="主石计法" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_MSPriceMethod" label="主石计法" width="120" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_MSPriceMethod" placeholder="请选择计价方式">
						<el-option key="1" label="计件" value="计件" />
						<el-option key="2" label="计重" value="计重" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_MSPriceMethod }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_MinStonePrice" label="主石单价" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_MinStonePrice" label="主石单价" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_MinStonePrice" />
					<div v-else>{{ scope.row.PurchaseDetailBill_MinStonePrice }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_MainStoneTotalPrice" label="主石价格" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_MainStoneTotalPrice" label="主石价格" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_MainStoneTotalPrice" />
					<div v-else>{{ scope.row.PurchaseDetailBill_MainStoneTotalPrice }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_AccessoryCategory_name" label="副石类别" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_AccessoryCategory_name" label="副石类别" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" @change="AScategoryclick"
						clearable v-model="updatedetailform.PurchaseDetailBill_AccessoryCategory_id"
						placeholder="请选择副石类别">
						<el-option v-for="item in basics.stonecategory" :key="item.StoneCategory_id"
							:label="item.StoneCategory_name" :value="item.StoneCategory_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_AccessoryCategory_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_AccessoryStoneWeight" :formatter="accessoryweight" label="副石重"
				width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_AccessoryStoneWeight" :formatter="accessoryweight" label="副石重"
				width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_AccessoryStoneWeight" />
					<div v-else>{{ scope.row.PurchaseDetailBill_AccessoryStoneWeight }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_AccessoryStoneQuantity" label="副石数量" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_AccessoryStoneQuantity" label="副石数量" width="90" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_AccessoryStoneQuantity" />
					<div v-else>{{ scope.row.PurchaseDetailBill_AccessoryStoneQuantity }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_ASPriceMethod" label="副石计法" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_ASPriceMethod" label="副石计法" width="120" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						@change="ASPriceMethodblur" clearable v-model="detailform.PurchaseDetailBill_ASPriceMethod"
						placeholder="请选择计价方式">
						<el-option key="1" label="计件" value="计件" />
						<el-option key="2" label="计重" value="计重" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_ASPriceMethod }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_AccessoryStonePrice" label="副石单价" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_AccessoryStonePrice" label="副石单价" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_AccessoryStonePrice" />
					<div v-else>{{ scope.row.PurchaseDetailBill_AccessoryStonePrice }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_AccessoryStoneTotalPrice" label="副石价格" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_AccessoryStoneTotalPrice" label="副石价格" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_AccessoryStoneTotalPrice" />
					<div v-else>{{ scope.row.PurchaseDetailBill_AccessoryStoneTotalPrice }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_StoneInlay_name" label="镶法" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_StoneInlay_name" label="镶法" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_StoneInlay_id" placeholder="请选择镶法">
						<el-option v-for="item in basics.stoneinlay" :key="item.StoneInlay_id"
							:label="item.StoneInlay_name" :value="item.StoneInlay_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_StoneInlay_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_StoneShape_name" label="形状" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_StoneShape_name" label="形状" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_StoneShape_id" placeholder="请选择形状">
						<el-option v-for="item in basics.stoneshape" :key="item.StoneShape_id"
							:label="item.StoneShape_name" :value="item.StoneShape_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_StoneShape_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_StoneColor_name" label="颜色" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_StoneColor_name" label="颜色" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_StoneColor_id" placeholder="请选择颜色">
						<el-option v-for="item in basics.stonecolor" :key="item.StoneColor_id"
							:label="item.StoneColor_name" :value="item.StoneColor_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_StoneColor_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_StoneClarity_name" label="净度" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_StoneClarity_name" label="净度" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_StoneClarity_id" placeholder="请选择净度">
						<el-option v-for="item in basics.stoneclarity" :key="item.StoneClarity_id"
							:label="item.StoneClarity_name" :value="item.StoneClarity_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_StoneClarity_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_StoneCut_name" label="车工" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_StoneCut_name" label="车工" width="150" align="center">
				<template #default="scope">
					<el-select v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" clearable
						v-model="updatedetailform.PurchaseDetailBill_StoneCut_id" placeholder="请选择车工">
						<el-option v-for="item in basics.stonecut" :key="item.StoneCut_id" :label="item.StoneCut_name"
							:value="item.StoneCut_id" />
					</el-select>
					<div v-else>{{ scope.row.PurchaseDetailBill_StoneCut_name }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_ProcessCost" label="加工费" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_ProcessCost" label="加工费" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_ProcessCost" />
					<div v-else>{{ scope.row.PurchaseDetailBill_ProcessCost }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_CertificateCost" label="证书费" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_CertificateCost" label="证书费" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_CertificateCost" />
					<div v-else>{{ scope.row.PurchaseDetailBill_CertificateCost }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_OtherCost" label="其他费" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_OtherCost" label="其他费" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_OtherCost" />
					<div v-else>{{ scope.row.PurchaseDetailBill_OtherCost }}</div>
				</template>
			</el-table-column>

			<!-- <el-table-column prop="PurchaseDetailBill_cost" label="成本" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_cost" label="成本" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_cost" />
					<div v-else>{{ scope.row.PurchaseDetailBill_cost }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_SalesRatio" label="销售倍率" width="90" /> -->
			<el-table-column prop="PurchaseDetailBill_SalesRatio" label="销售倍率" width="90" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_SalesRatio" />
					<div v-else>{{ scope.row.PurchaseDetailBill_SalesRatio }}</div>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="PurchaseDetailBill_SalesPrice" label="销售总价" width="100" /> -->
			<el-table-column prop="PurchaseDetailBill_SalesPrice" label="销售总价" width="100" align="center">
				<template #default="scope">
					<el-input v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id"
						oninput="value = value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')"
						v-model="updatedetailform.PurchaseDetailBill_SalesPrice" />
					<div v-else>{{ scope.row.PurchaseDetailBill_SalesPrice }}</div>
				</template>
			</el-table-column>
			<el-table-column fixed="right" align="center" label="操作" width="150" v-if="billstate == '未确认'">
				<template #default="scope">
					<el-button v-if="tableRowEditId_detail == scope.row.PurchaseDetailBill_id" type="text"
						@click="updatedetail_save(scope.row)" :icon="EditPen">保存</el-button>
					<el-button v-else type="text" @click="updatedetail(scope.row)" :icon="EditPen">修改</el-button>



					<el-popconfirm title="操作不可撤销,是否确认删除？" confirmButtonText="确定" cancelButtonText="取消"
						@confirm="deletedetail(scope.row)">
						<template #reference>
							<el-button class="operate" type="text" :icon="Delete">删除</el-button>
						</template>
					</el-popconfirm>

				</template>
			</el-table-column>
		</el-table>
	</el-drawer>
	<!-- 新增明细项目 -->
	<el-dialog draggable v-model="detaildialog" title="添加商品" width="740px">
		<el-scrollbar height="60vh">
			<el-form :rules="detailformrule" style="padding-left: 16px; padding-right: 16px; padding-top: 10px"
				ref="detailformref" :model="detailform" label-width="85px">
				<el-divider style="margin-bottom: 40px" content-position="center">商品信息</el-divider>
				<el-row style="margin-left: -20px; margin-right: -7.5px">
					<el-col :span="8">
						<el-form-item label="商品品牌:" prop="PurchaseDetailBill_GoodsBrand_name">
							<el-select clearable v-model="detailform.PurchaseDetailBill_GoodsBrand_id"
								placeholder="请选择品牌">
								<el-option v-for="item in basics.goodsbrand" :key="item.GoodsBrand_id"
									:label="item.GoodsBrand_name" :value="item.GoodsBrand_id" />
							</el-select>
						</el-form-item>
						<el-form-item label="商品成色:" prop="PurchaseDetailBill_GoodsGrade_name">
							<el-select clearable v-model="detailform.PurchaseDetailBill_GoodsGrade_id"
								placeholder="请选择成色">
								<el-option v-for="item in basics.goodsgrade" :key="item.GoodsGrade_id"
									:label="item.GoodsGrade_name" :value="item.GoodsGrade_id" />
							</el-select>
						</el-form-item>
						<el-form-item label="证书号:" prop="PurchaseDetailBill_CertificateNo">
							<el-input v-model="detailform.PurchaseDetailBill_CertificateNo" placeholder="请输入证书号" />
						</el-form-item>
						<el-form-item label="手寸:" prop="PurchaseDetailBill_RingSize">
							<el-input @change="RingSizeblur" v-model="detailform.PurchaseDetailBill_RingSize"
								placeholder="请输入手寸" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="商品系列:" prop="PurchaseDetailBill_GoodsSeries_name">
							<el-select clearable v-model="detailform.PurchaseDetailBill_GoodsSeries_id"
								placeholder="请选择系列">
								<el-option v-for="item in basics.goodsseries" :key="item.GoodsSeries_id"
									:label="item.GoodsSeries_name" :value="item.GoodsSeries_id" />
							</el-select>
						</el-form-item>
						<el-form-item label="商品款号:" prop="PurchaseDetailBill_StyleNumber">
							<el-input v-model="detailform.PurchaseDetailBill_StyleNumber" placeholder="请输入款号" />
						</el-form-item>
						<el-form-item label="原编号:" prop="PurchaseDetailBill_OriginalNumber">
							<el-input v-model="detailform.PurchaseDetailBill_OriginalNumber" placeholder="请输入原编号" />
						</el-form-item>
						<el-form-item label="总重:" prop="PurchaseDetailBill_TotalWeight">
							<el-input @change="TotalWeightblur" v-model="detailform.PurchaseDetailBill_TotalWeight"
								placeholder="请输入总重">
								<template #append>{{ TotalWeightUnit }}</template>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="商品种类:" prop="PurchaseDetailBill_GoodsCategory_id">
							<el-select @change="goodscategoryclick" clearable
								v-model="detailform.PurchaseDetailBill_GoodsCategory_id" placeholder="请选择种类">
								<el-option v-for="item in basics.goodcategory" :key="item.GoodsCategory_id"
									:label="item.GoodsCategory_name" :value="item.GoodsCategory_id" />
							</el-select>
						</el-form-item>
						<el-form-item label="商品名称:" prop="PurchaseDetailBill_name">
							<el-input v-model="detailform.PurchaseDetailBill_name" placeholder="请输入商品名称" />
						</el-form-item>
						<el-form-item label="计价方式:" prop="PurchaseDetailBill_PriceMethod">
							<el-select clearable v-model="detailform.PurchaseDetailBill_PriceMethod"
								placeholder="请选择计价方式">
								<el-option key="1" label="计件" value="计件" />
								<el-option key="2" label="计重" value="计重" />
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-divider style="margin-top: 30px; margin-bottom: 40px" content-position="center">金料信息</el-divider>
				<el-row style="margin-left: -20px; margin-right: -7.5px">
					<el-col :span="8">
						<el-form-item label="金重:" prop="PurchaseDetailBill_GoldWeight">
							<el-input @change="GoldWeightblur" v-model="detailform.PurchaseDetailBill_GoldWeight"
								placeholder="请输入金重">
								<template #append>g</template>
							</el-input>
						</el-form-item>
						<el-form-item label="金成本:" prop="PurchaseDetailBill_CleanGoldPrice">
							<el-input @change="CleanGoldPriceblur"
								v-model="detailform.PurchaseDetailBill_CleanGoldPrice" placeholder="请输入金成本" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="金价:" prop="PurchaseDetailBill_GoldPrice">
							<el-input @change="GoldPriceblur" v-model="detailform.PurchaseDetailBill_GoldPrice"
								placeholder="请输入金价" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="耗损:" prop="PurchaseDetailBill_WearRate">
							<el-input @change="WearRateblur" v-model="detailform.PurchaseDetailBill_WearRate"
								placeholder="请输入耗损">
								<template #append>g</template>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-divider style="margin-top: 30px; margin-bottom: 40px" content-position="center">宝石信息</el-divider>
				<el-row style="margin-left: -20px; margin-right: -7.5px">
					<el-col :span="8">
						<el-form-item label="宝石镶法:" prop="PurchaseDetailBill_StoneInlay_name">
							<el-select clearable v-model="detailform.PurchaseDetailBill_StoneInlay_id"
								placeholder="请选择镶法">
								<el-option v-for="item in basics.stoneinlay" :key="item.StoneInlay_id"
									:label="item.StoneInlay_name" :value="item.StoneInlay_id" />
							</el-select>
						</el-form-item>
						<el-form-item label="宝石净度:" prop="PurchaseDetailBill_StoneClarity_name">
							<el-select clearable v-model="detailform.PurchaseDetailBill_StoneClarity_id"
								placeholder="请选择净度">
								<el-option v-for="item in basics.stoneclarity" :key="item.StoneClarity_id"
									:label="item.StoneClarity_name" :value="item.StoneClarity_id" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="宝石形状:" prop="PurchaseDetailBill_StoneShape_name">
							<el-select clearable v-model="detailform.PurchaseDetailBill_StoneShape_id"
								placeholder="请选择形状">
								<el-option v-for="item in basics.stoneshape" :key="item.StoneShape_id"
									:label="item.StoneShape_name" :value="item.StoneShape_id" />
							</el-select>
						</el-form-item>
						<el-form-item label="宝石车工:" prop="PurchaseDetailBill_StoneCut_name">
							<el-select clearable v-model="detailform.PurchaseDetailBill_StoneCut_id"
								placeholder="请选择车工">
								<el-option v-for="item in basics.stonecut" :key="item.StoneCut_id"
									:label="item.StoneCut_name" :value="item.StoneCut_id" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="宝石颜色:" prop="PurchaseDetailBill_StoneColor_name">
							<el-select clearable v-model="detailform.PurchaseDetailBill_StoneColor_id"
								placeholder="请选择颜色">
								<el-option v-for="item in basics.stonecolor" :key="item.StoneColor_id"
									:label="item.StoneColor_name" :value="item.StoneColor_id" />
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row style="margin-left: -20px; margin-right: -7.5px">
					<el-col :span="8">
						<el-form-item label="主石类别:" prop="PurchaseDetailBill_MainStoneCategory_name">
							<el-select @change="MScategoryclick" clearable
								v-model="detailform.PurchaseDetailBill_MainStoneCategory_id" placeholder="请选择主石类别">
								<el-option v-for="item in basics.stonecategory" :key="item.StoneCategory_id"
									:label="item.StoneCategory_name" :value="item.StoneCategory_id" />
							</el-select>
						</el-form-item>
						<el-form-item label="主石重:" prop="PurchaseDetailBill_MainStoneWeight">
							<el-input @change="MainStoneWeightblur"
								v-model="detailform.PurchaseDetailBill_MainStoneWeight" placeholder="请输入重量">
								<template #append>{{ MSWeightUnit }}</template>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="石价计法:" prop="PurchaseDetailBill_MSPriceMethod">
							<el-select @change="MSPriceMethodblur" clearable
								v-model="detailform.PurchaseDetailBill_MSPriceMethod" placeholder="请选择计价方式">
								<el-option key="1" label="计件" value="计件" />
								<el-option key="2" label="计重" value="计重" />
							</el-select>
						</el-form-item>
						<el-form-item label="主石单价:" prop="PurchaseDetailBill_MinStonePrice">
							<el-input @change="MinStonePriceblur" v-model="detailform.PurchaseDetailBill_MinStonePrice"
								placeholder="请输入单价" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="主石数量:" prop="PurchaseDetailBill_MinStoneQuantity">
							<el-input @change="MinStoneQuantityblur"
								v-model="detailform.PurchaseDetailBill_MinStoneQuantity" placeholder="请输入数量" />
						</el-form-item>
						<el-form-item label="主石价格:" prop="PurchaseDetailBill_MainStoneTotalPrice">
							<el-tooltip placement="right">
								<template #content> 自动计算规则:<br />计件:主石单价*主石数量<br />计重:主石单价*主石重量 </template>
								<el-input v-model="detailform.PurchaseDetailBill_MainStoneTotalPrice"
									placeholder="请输入主石价格" />
							</el-tooltip>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row style="margin-left: -20px; margin-right: -7.5px">
					<el-col :span="8">
						<el-form-item label="副石类别:" prop="PurchaseDetailBill_AccessoryCategory_name">
							<el-select @change="AScategoryclick" clearable
								v-model="detailform.PurchaseDetailBill_AccessoryCategory_id" placeholder="请选择副石类别">
								<el-option v-for="item in basics.stonecategory" :key="item.StoneCategory_id"
									:label="item.StoneCategory_name" :value="item.StoneCategory_id" />
							</el-select>
						</el-form-item>
						<el-form-item label=" 副石重:" prop="PurchaseDetailBill_AccessoryStoneWeight">
							<el-input @change="AccessoryStoneWeightblur"
								v-model="detailform.PurchaseDetailBill_AccessoryStoneWeight" placeholder="请输入重量">
								<template #append>{{ ASWeightUnit }}</template>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="石价计法:" prop="PurchaseDetailBill_ASPriceMethod">
							<el-select @change="ASPriceMethodblur" clearable
								v-model="detailform.PurchaseDetailBill_ASPriceMethod" placeholder="请选择计价方式">
								<el-option key="1" label="计件" value="计件" />
								<el-option key="2" label="计重" value="计重" />
							</el-select>
						</el-form-item>
						<el-form-item label="副石单价:" prop="PurchaseDetailBill_AccessoryStonePrice">
							<el-input @change="AccessoryStonePriceblur"
								v-model="detailform.PurchaseDetailBill_AccessoryStonePrice" placeholder="请输入单价" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="副石数量:" prop="PurchaseDetailBill_AccessoryStoneQuantity">
							<el-input @change="AccessoryStoneQuantityblur"
								v-model="detailform.PurchaseDetailBill_AccessoryStoneQuantity" placeholder="请输入数量" />
						</el-form-item>
						<el-form-item label="副石价格:" prop="PurchaseDetailBill_AccessoryStoneTotalPrice">
							<el-tooltip placement="right">
								<template #content> 自动计算规则:<br />计件:副石单价*副石数量<br />计重:副石单价*副石重量 </template>
								<el-input v-model="detailform.PurchaseDetailBill_AccessoryStoneTotalPrice"
									placeholder="请输入副石价格" />
							</el-tooltip>
						</el-form-item>
					</el-col>
				</el-row>
				<el-divider style="margin-top: 30px; margin-bottom: 40px" content-position="center">费用价格</el-divider>
				<el-row style="margin-left: -20px; margin-right: -7.5px">
					<el-col :span="8">
						<el-form-item label="工费计法:" prop="PurchaseDetailBill_CostMethod">
							<el-select @change="CostMethodblur" clearable
								v-model="detailform.PurchaseDetailBill_CostMethod" placeholder="请选择计价方式">
								<el-option key="1" label="计件" value="计件" />
								<el-option key="2" label="计重" value="计重" />
							</el-select>
						</el-form-item>
						<el-form-item label="其他费:" prop="PurchaseDetailBill_OtherCost">
							<el-input @change="OtherCostblur" v-model="detailform.PurchaseDetailBill_OtherCost"
								placeholder="请输入其他费" />
						</el-form-item>
						<el-form-item label="销售价:" prop="PurchaseDetailBill_SalesPrice">
							<el-input v-model="detailform.PurchaseDetailBill_SalesPrice" placeholder="请输入销售价" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item type="number" label="加工费:" prop="PurchaseDetailBill_ProcessCost">
							<el-input @change="ProcessCostblur" v-model="detailform.PurchaseDetailBill_ProcessCost"
								placeholder="请输入加工费" />
						</el-form-item>
						<el-form-item label="成本:" prop="PurchaseDetailBill_cost">
							<el-input v-model="detailform.PurchaseDetailBill_cost" placeholder="请输入成本" />
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="证书费:" prop="PurchaseDetailBill_CertificateCost">
							<el-input @change="CertificateCostblur"
								v-model="detailform.PurchaseDetailBill_CertificateCost" placeholder="请输入证书费" />
						</el-form-item>
						<el-form-item label="销售倍率:" prop="PurchaseDetailBill_SalesRatio">
							<el-input @change="SalesRatioblur" v-model="detailform.PurchaseDetailBill_SalesRatio"
								placeholder="请输入销售倍率" />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</el-scrollbar>
		<template #footer>
			<span class="dialog-footer">
				<el-checkbox style="margin-right: 20px" v-model="autochecked" label="自动计算" checked true-label="1"
					false-label="0" />
				<el-button>取消</el-button>
				<el-button @click="submitdetailform(detailformref)" type="primary">确认</el-button>
			</span>
		</template>
	</el-dialog>

	<!-- 检查基础资料弹出框 -->
	<el-dialog :before-close="basicsbeforeclose" v-model="miss_basicdatatable_drawer"
		:title="'检测到新增基础资料共' + miss_basicdata_count + '条,' + '是否添加？'" width="400px">
		<el-table :data="miss_basicdata_table" max-height="250" table-layout="fixed"
			:header-cell-style="{ color: '#000000' }">
			<el-table-column property="field" label="类型" />
			<el-table-column property="value" label="名称" />
		</el-table>
		<template #footer>
			<div class="dialog-footer">
				<el-button @click="cancelmissbasicdata">取消</el-button>
				<el-button type="primary" @click="addbascdata"> 添加 </el-button>
			</div>
		</template>
	</el-dialog>
</template>

<style lang="less" scoped>
.el-card_body {
	background-color: white;
	padding: 15px;
}

.box-card {
	margin-top: 30px;
	// border-bottom: none;
	height: 55vh;
	border: none;
}

.card-header {
	font-size: 14px;
	font-weight: 500;
}

/deep/.el-card__header {
	padding: calc(var(--el-card-padding) - 14px) var(--el-card-padding);
	background-color: #f6f8f9;
	padding-left: 10px;
}

.roleformclass {
	margin-bottom: 15px;
}

/deep/.roleformclass.el-form--inline .el-form-item {
	margin-right: 15px;
}

.ele-table-tool {
	display: inline-flex;
	flex-wrap: wrap;
	width: 100%;
}

.ele-tool {
	margin: 5px 0 5px auto;
}

.ele-pagination {
	margin-top: 15px;
	display: flex;
	justify-content: center;
}

/deep/ .operate {
	color: red;
}

/deep/.operate2 {
	color: #52c41a;
}

/deep/.operate3 {
	color: gray;
}

/deep/.reset {
	color: #52c41a;
}

/deep/.cell-item {
	display: flex;
	align-items: center;
}

.margin-top {
	margin-top: -9px;
	margin-left: 47px;
	// margin-bottom: 20px;
	// margin-right: 20px;
}

.vab-table-expand {
	padding: 20px;
	line-height: 30px;
}

.vab-table-expand-title {
	display: inline-block;
	width: 50px;
	font-weight: 700;
}

.upload_class {
	display: contents;
}

/deep/.el-upload {
	margin-left: 4px;
}
</style>
